/*
 * @Description: 
 * @Author: 赵大壮
 * @Date: 2021-12-06 17:18:37
 * @LastEditTime: 2021-12-31 13:22:31
 * @LastEditors: 赵大壮
 */
import { Component, Vue, Inject, Watch } from "vue-property-decorator";

@Component({
    components: {}
})
export default class Index extends Vue {

    onRoutes = this.$route.path;

    // items = [];
    items = [];

    get user() {
        return this.$store.state.user;
    }



    created() {
        let userRole: Array<any> = [];
        if (this.user.roleInfo) {
            userRole = JSON.parse(this.user.roleInfo)
        }
        let mainMenu: Array<any> = this.$dzSystem.arr_menuList;
        let newNenu = [];
        console.log("userRole====", userRole)
        if (userRole.length == 0) {
            this.items = mainMenu;
            return;
        }
        for (const index in mainMenu) {
            let item = mainMenu[index];
            if (!item.subs) {
                if (userRole.indexOf(item.id) >= 0) {
                    newNenu.push(item)
                }
            } else {
                if (userRole.indexOf(item.id) >= 0) {
                    newNenu.push(item)
                } else {
                    let newSubs = [];
                    for (const iterator of item.subs) {
                        if (userRole.indexOf(iterator.id) >= 0) {
                            newSubs.push(iterator)
                        }
                    }
                    if (newSubs.length > 0) {
                        item.subs = newSubs;
                        newNenu.push(item)
                    }
                }
            }
        }
        console.log("mainMenu===", newNenu)
        this.items = newNenu;
    }

    mounted() {
    }

    beforeDestroy() {

    }

    /**
     * 菜单激活回调
     * @param key 
     * @param keyPath 
     */
    selectSide(key: any, keyPath: any) {
        this.$dzSystem.onRoutes = keyPath;
    }


}